/*
 * Simulation.h
 *
 *  Created on: Jan 24, 2010
 *      Author: snirgaz
 */

#ifndef SIMULATION_H_
#define SIMULATION_H_

#include "HelpLibs/def.h"
#include "WorldLines.h"
#include "RandomWalks.h"
#include "EnergyCalc.h"
#include "Measure.h"
#include "HelpLibs/RandomGen.h"
#include "HelpLibs/QmcParameters.h"
#include "Bisection.h"
#include "SimParams.h"
#include "HelpLibs/InputFile.h"
#include "move.cpp"

class Qmc {
private:
	WorldLines wl_;
	Bisection bisection_;
	MoveParams moveParams_;
	// energy Calculation
	EnergyCalc energyCalc_;
	// Moves
	OpenMove openMove_;
	CloseMove closeMove_;
	WiggleMove wiggleMove_;
	SwapMove swapMove_;
	QmcParameters qmcParams_;
	SimulationParameters simParams_;
	UniformInt nextMove_;
	statistics stats_;
	ofstream outPutFile_;

public:
	void init(QmcParameters &qmcParams);
	//Initialize Configurations
	void initConf();
	void initializeWLDataFromFile(String fileName);
	void initializeFromFile();
	void thermalize();
	void runN(int n);
	bool run();
	bool nextMove();
	double calcRhoOpenClose();
	bool rhoSwap(double &swapRatio);
	void sigmaSwap(int wl, DoubleVec & rho);
	void dump();
	void dump_params();
	void updatePath(std::string &path);
	void updateLambda(double lambda);
	void updateRS(double rs);
	bool checkSweep(OC OpenClose);
	void adjustGamma();
	void updateRs(double rs);
	void clearStats();
	void swapWL(Qmc &Qmc2);
	void reCalcEnergy();
	// Debug
	bool EKcheck(int step, int move);
	bool loopCheck(int step);
	void performMeasure();
	bool measureDone();
	int getSweepRate();
	double getLambda();
	WLEnergyData getED();
	double getEK();
	bool energy_diff(int step);
	void printEnergyDiff();
	void getEnergyCalcEnergy(WLEnergyData &E1, WLEnergyData &E2);
	bool isClosed();
	void setNumOfThermal(int numThermal);
	void initializeCountOutput();
};

bool
accept(double p, VSLStreamStatePtr& stream);

#endif /* SIMULATION_H_ */

